package com.rst.dao;

import java.util.List;

import org.hibernate.Query;
import org.hibernate.Session;
import org.hibernate.SessionFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Repository;
import org.springframework.transaction.annotation.Transactional;

import com.rst.model.Classe;

@Repository
@Transactional
public class ClassDAO {

	@Autowired
	private SessionFactory sessionFactory;


	public Long saveClass(Classe clas) {
		return (Long) sessionFactory.getCurrentSession().save(clas);
	}

	public Classe getClassById(Long classId) {
	    Session session = sessionFactory.getCurrentSession();
	    Classe clas = (Classe)session.get(Classe.class, classId);
		return clas;
	}

	public Long udateClass(Classe class1) {
		sessionFactory.getCurrentSession().update(class1);
		return class1.getClassId();
	}

	@SuppressWarnings("unchecked")
	public List<Classe> getClassList() {
		Session session = sessionFactory.getCurrentSession();
	    String str = "FROM Classe c WHERE c.status = :status ORDER BY c.name ";
	    	
	    Query query = session.createQuery(str);
	    query.setParameter("status",  Classe.ACTIVE);
		return query.list();

		
/*		Criteria criteria = sessionFactory.getCurrentSession().createCriteria(Class.class);
		criteria.addOrder(Order.asc("name"));
		return criteria.list();
*/	
		}

}
